let info = {
  name: "zhu",
  tel: "134xxxxx320",
};
let otherInfo = {
  name: "zhang",
  age: "18",
  address: "gd",
};
//方式1：通过逐一赋值的方式合并，这种方式非常 ugly，随着 key 值越多，代码 ugly 的程度会急剧增加
info.age = otherInfo.age;
info.address = otherInfo.address;
console.log(info); //{ name: 'zhu', tel: '134xxxxx320', age: '18', address: 'gd' }

//方式2：扩展运算符
info = { ...info, ...otherInfo };
console.log(info); //{ name: 'zhang', tel: '134xxxxx320', age: '18', address: 'gd' }

//方式3；object.assign方法(ES6中的方法)
Object.assign(info, otherInfo);
console.log(info); //{ name: 'zhang', tel: '134xxxxx320', age: '18', address: 'gd' }

//方式4:创建一个新对象合并这两个对象
let newObject = Object.assign({}, info, otherInfo);
console.log(newObject); //{ name: 'zhang', tel: '134xxxxx320', age: '18', address: 'gd' }

//方式5:封装一个方法
function extend(target, souce) {
  for (var key in souce) {
    target[key] = souce[key];
  }
  return target;
}
console.log(extend(info, otherInfo));
//{ name: 'zhang', tel: '134xxxxx320', age: '18', address: 'gd' }
